package com.wdh.kjs.fragment;

import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.Adapter.InvestmentListAdapter;
import com.wdh.kjs.Adapter.ListViewForScrollView;
import com.wdh.kjs.R;
import com.wdh.kjs.activity.InvestmentDetailActivity;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.model.JsonModel;
import com.wdh.kjs.util.ToastUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by codingWw on 2016/3/7.
 */
public class InvestmentDetailTwoFragment extends Fragment {
    private TextView tv_idt_username;
    private TextView tv_idt_userphone;
    private TextView tv_idt_useremail;
    private TextView tv_idt_useraddress;
    private TextView tv_idt_companyname;
    private TextView tv_idt_companyxinxi;
    private JsonModel jsonModel;
    private LinearLayout ii_fg2_investdetail_companyname;
    private LinearLayout ii_fg2_investdetail_companymessage;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_investmentdetail_two, container, false);
        tv_idt_username = (TextView) view.findViewById(R.id.tv_idt_username);
        ii_fg2_investdetail_companyname = (LinearLayout) view.findViewById(R.id.ii_fg2_investdetail_companyname);
        ii_fg2_investdetail_companymessage = (LinearLayout) view.findViewById(R.id.ii_fg2_investdetail_companymessage);
        tv_idt_userphone = (TextView) view.findViewById(R.id.tv_idt_userphone);
        tv_idt_useremail = (TextView) view.findViewById(R.id.tv_idt_useremail);
        tv_idt_useraddress = (TextView) view.findViewById(R.id.tv_idt_useraddress);
        tv_idt_companyname = (TextView) view.findViewById(R.id.tv_idt_companyname);
        tv_idt_companyxinxi = (TextView) view.findViewById(R.id.tv_idt_companyxinxi);
        if (InvestmentDetailActivity.type.equals("p")){
            ii_fg2_investdetail_companyname.setVisibility(View.GONE);
            ii_fg2_investdetail_companymessage.setVisibility(View.GONE);
        }else {
            ii_fg2_investdetail_companyname.setVisibility(View.GONE);
            ii_fg2_investdetail_companymessage.setVisibility(View.GONE);
        }
        intweb();
        return view;
    }

    private void intweb() {
        RequestParams params = new RequestParams();

        params.addBodyParameter("itemId", InvestmentDetailActivity.itemId);
        params.addBodyParameter("page", 1 + "");
        params.addBodyParameter("rows", "1");
        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_Invest_DETAIL, params, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {


                Gson gson = new Gson();
                jsonModel = gson.fromJson(responseInfo.result, JsonModel.class);

                if (jsonModel.success) {

                    item();
                }


            }

            @Override
            public void onFailure(HttpException error, String msg) {

                ToastUtils.showShort(getActivity(), "网络异常！");
            }
        });

    }

    private void item() {
        tv_idt_companyname.setText(jsonModel.getItem().getCompanyName());
        tv_idt_username.setText(jsonModel.getItem().getContactName());
        tv_idt_userphone.setText(jsonModel.getItem().getContactTel());
        tv_idt_useremail.setText(jsonModel.getItem().getContactEmail());
        tv_idt_useraddress.setText(jsonModel.getItem().getLocalProvince()+jsonModel.getItem().getLocalCity()+jsonModel.getItem().getLocalCounty());
        tv_idt_companyxinxi.setText(jsonModel.getItem().getTeamIntroduction());
    }

}
